﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data.Linq;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Stamp_For_Africa_Version_2.Repositories;

namespace Stamp_For_Africa_Version_2.Models
{

	public enum IssueType
	{
		RegularIssue,
		Provisional,
		Commemorative
	}

  public partial class Stamp
  {
    public bool IsValid
    {
      get { return (GetRuleViolations().Count() == 0); }
    }

    public Guid CatalogueId { get; set; }
    public int CatalogueNumber { get; set; }

    public bool InMyCollection { get; set; }
    public int MintNeverHingedCount { get; set; }
    public int MintHingedCount { get; set; }
    public int UsedCount { get; set; }
    public bool IsSelected { get; set; }
		public int GetTotalCount()
		{
			return MintNeverHingedCount + MintHingedCount + UsedCount;
		}
		public float ValueOfCollection
		{
			get
			{
				return (float)((ValueMintNeverHinged * MintNeverHingedCount) + (ValueMintHinged * MintHingedCount) + (ValueUsed*UsedCount));
			}
			
		}

    public IEnumerable<RuleViolation> GetRuleViolations()
    {
      if (String.IsNullOrEmpty(DisplayName))
        yield return new RuleViolation("Display name required", "DisplayName");


			//if (String.IsNullOrEmpty(UploadedFileName))
			//	yield return new RuleViolation("Please select the stamp image", "Stamp image");

      //if (CountryId == Guid.Empty)
      //  yield return new RuleViolation("Country required", "Country");

      //if (Image == null)
      //  yield return new RuleViolation("Stamp image required", "Image");

      //if (UploaderId == Guid.Empty)
      //  yield return new RuleViolation("Uploader required", "Uploader");

      //if (PrimaryColorId == Guid.Empty)
      //  yield return new RuleViolation("Primary colour required", "Colour");

      //if (String.IsNullOrEmpty(MainIdentifier))
      //  yield return new RuleViolation("Main Identifier required", "MainIdentifier");

      //if (ArtistId == Guid.Empty)
      //  yield return new RuleViolation("Artist required", "Artist");

      if (String.IsNullOrEmpty(SearchTags1))
        yield return new RuleViolation("Search tags required", "SearchTags1");

      yield break;
    }

    partial void OnValidate(ChangeAction action)
    {
      if (!IsValid)
        throw new ApplicationException("Rule violations prevent saving");
    }

		#region Model Helpers

    public float MatchProbability { get; set; }
		  
  	public SelectList Colours
  	{
  		get
  		{
  			ColourRepository repository = new ColourRepository();
				return new SelectList(repository.FindAllColours(), "Id", "Colour1", PrimaryColorId);
  		}
  	}

  	public SelectList Uploaders
  	{
			get
			{
				UploaderRepository repository = new UploaderRepository();
				return new SelectList(repository.FindAllUploaders(), "Id", "Name", UploaderId);
			}  		
  	}

  	public SelectList Currencies
  	{
  		get
  		{
  			CurrencyRepository repository = new CurrencyRepository();
				return new SelectList(repository.FindAllCurrencies(), "Id", "DisplayName", CurrencyId);
  		}
  	}
    
   
		public String UploadedFileName { get; set; }
		public String NonRootedUploadedFileName { get; set; }

		public String UploadedControlBlockFileName { get; set; }
		public String NonRootedUploadedControlBlockFileName { get; set; }

    public String UploadedMinatureSheetFileName { get; set; }
    public String NonRootedUploadedMinatureSheetFileName { get; set; }

  	public String ShortFromDate
  	{
			get { return FromDate.ToString(); }
  	}
  	public String ShortToDate
  	{
			get { return ToDate.ToString(); }
  	}

  	public bool IsAVariation
  	{
  		get
  		{
  			StampRepository stampRepository = new StampRepository();
  			return stampRepository.IsAStampVariant(Id);
  		}
  	}
  	public Stamp StampVariantParent
  	{
  		get
  		{
  			StampRepository stampRepository = new StampRepository();
  			return stampRepository.GetParentStampOfVariant(Id);
  		}
  	}

		#endregion
	}
}